package com.tvein.sanguo.room.view
{
	//flash
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	//pureMVC
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.mediator.FlashMediator;
	//custom
	import com.tvein.sanguo.room.common.GameConstants;
	import com.tvein.sanguo.room.model.SystemProxy;
	import com.tvein.sanguo.Room;
	import com.tvein.sanguo.swc.room.RoomShell;
//
	public class RoomMediator extends FlashMediator
	{
		static public const NAME : String = "RoomMediator";
		
		public function RoomMediator(viewComponent:Object)
		{
			super(NAME, viewComponent);
		}
		
		public function get room() : Room
		{
			return viewComponent as Room;
		}
		
		//Custom
		private var systemData:SystemProxy;
		public var roomShell:RoomShell;
		
		override public function onRegister() : void
		{			
			systemData = facade.retrieveProxy(SystemProxy.NAME) as SystemProxy;
			
			room.visible = false;
			
			roomShell = new RoomShell();
			
			room.addChild(roomShell);
			
			var params:Object = new Object();
			params.Volume = systemData.effectVol;
			roomShell.console("setEffect", params);
			
			roomShell.addEventListener("RoomShell", _handleEvents);
		}
		
		private function _handleEvents(evt:Object):void
		{
			if (evt.cmd[0] == "buttonCMD")
			{
				routeNotification(GameConstants.GAME_CONSOLE, ["-gameCommand", evt.cmd[1]], null, "*");
			}
			else if (evt.cmd[0] == "privateChat")
			{
				routeNotification(GameConstants.MODULE_INVOKE, ["-init", ["chat", evt.cmd[1]]], null, GameConstants.MODULE_CHAT + "/*");
			}
		}
	}
}